<template>
  <div>
    <head-top
      routerName="myInvitation"
      title="我的邀请"
      :blackRadian="false"
    ></head-top>
    <div class="black"></div>
    <div class="content-wrap">
      <div class="InvitationTotal">
        <ul>
          <li>
            <div class="data">{{ myInv.directNum }}</div>
            <div class="label">我的邀请</div>
          </li>
          <li>
            <div class="data">{{ myInv.teamNum }}</div>
            <div class="label">我的团队</div>
          </li>
        </ul>
      </div>
      <div class="list">
        <div class="title">我的直推</div>
        <van-pull-refresh
          v-model="refreshing"
          success-text="刷新成功"
          @refresh="onRefresh"
        >
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text=""
            @load="onLoad"
          >
            <ul>
              <li>
                <span class="name">昵称</span>
                <span>直推</span>
                <span>团队</span>
              </li>
              <li v-for="(item, index) in directList" :key="index">
                <span>{{ item.nickName }}</span>
                <span>{{ item.directNum }}</span>
                <span>{{ item.teamNum }}</span>
              </li>
            </ul>
          </van-list>
        </van-pull-refresh>
      </div>
    </div>
  </div>
</template>
<script>
import { PullRefresh, List } from "vant";
import HeadTop from "@/components/head";
import { queryInvList } from "@/api/myInvitation";
import { getUserId } from "@/utils/APPempower";

export default {
  components: {
    HeadTop,
    [PullRefresh.name]: PullRefresh,
    [List.name]: List,
  },
  data() {
    return {
      formData: {
        userId: getUserId(),
        pageNo: 1,
        pageSize: 10,
      },
      refreshing: false,
      loading: false,
      finished: false,
      directList: [],
      myInv: [],
    };
  },
  methods: {
    onLoad() {
      queryInvList(this.formData).then((res) => {
        if (res.data.resultStatus) {
          var directList = res.data.resultData.directList;
          if (directList && directList.length < 10) {
            this.finished = true;
          } else {
            this.finished = false;
          }
          if (this.refreshing) {
            this.directList = directList;
          } else {
            this.directList = this.directList.concat(directList);
          }
          this.myInv = res.data.resultData.myInv;
          this.formData.pageNo++;
          this.loading = false;
          this.refreshing = false;
        } else {
          this.finished = true;
        }
      });
    },
    onRefresh() {
      this.formData.pageNo = 1;
      this.onLoad();
    },
  },
};
</script>
<style lang="less" scoped>
.black {
  position: absolute;
  left: 0;
  right: 0;
  height: 89px;
  background: #333333;
}
/deep/.van-loading {
  margin: 0;
}
.content-wrap {
  position: relative;
  z-index: 1;
  background: none;
  .InvitationTotal {
    padding-top: 31px;
    ul {
      display: flex;
      align-items: center;
      background: #ffffff;
      height: 90px;
      text-align: center;
      box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.06);
      border-radius: 2px;
      li {
        position: relative;
        flex: 1;
        width: 50%;
        .data {
          line-height: 16px;
          font-size: 16px;
          font-weight: bold;
          color: #333333;
        }
        .label {
          margin-top: 10px;
          font-size: 11px;
          font-weight: 300;
          color: #999999;
        }
        &:first-child {
          &:after {
            position: absolute;
            content: "";
            top: 50%;
            right: 0;
            width: 1px;
            height: 28px;
            margin-top: -14px;
            border-right: 1px solid #f1f1f1;
          }
        }
      }
    }
  }
  .list {
    margin-top: 13px;
    background: #ffffff;
    box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.06);
    border-radius: 2px;
    .title {
      padding: 10px;
      height: 20px;
      font-size: 14px;
      font-weight: 500;
      color: #333333;
      line-height: 20px;
    }
    .van-list {
      min-height: 55vh;
    }
    ul {
      margin-top: 3px;
      li {
        display: flex;
        justify-content: space-between;
        padding-bottom: 10px;
        span {
          flex: 1;
          width: 100%;
          text-align: center;
          height: 20px;
          font-size: 14px;
          font-weight: 400;
          color: #333333;
          line-height: 20px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
}
</style>